package hwThree5;


import edu.princeton.cs.algs4.LinearProbingHashST;
import edu.princeton.cs.algs4.StdOut;

public class HashSET<Key extends Comparable<Key>> {
    private LinearProbingHashST<Key, Boolean> st;
    public HashSET() {
        st = new LinearProbingHashST<>();
    }
    public void add(Key key) {
        st.put(key, true);
    }
    public boolean contains(Key key) {
        return st.contains(key);
    }
    public Iterable<Key> keys() {
        return st.keys(); // 返回符号表中所有键
    }
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (Key key : st.keys()) {
            sb.append(key).append(" ");
        }
        return sb.toString().trim();
    }

    public static void main(String[] args) {
        HashSET<String> set = new HashSET<>();

        set.add("A");
        set.add("b");
        set.add("C");

        StdOut.println("Contains A? " + set.contains("A"));
        StdOut.println("Contains B? " + set.contains("B"));
    }
}
